package LinkedListPackage2;

import LinkedListPackage.ListNode;

/**
 * @author Lzm
 * @version 1.0
 */
public class removeElements_ {
  public static void main(String[] args) {
    ListNode node1 = new ListNode(1);
    ListNode node2 = new ListNode(2);
    ListNode node3 = new ListNode(6);
    ListNode node4 = new ListNode(3);
    ListNode node5 = new ListNode(4);

    node1.next = node2;
    node2.next = node3;
    node3.next = node4;
    node4.next = node5;
    removeElements(node1,6);
  }

  public static ListNode removeElements(ListNode head, int val) {
    if (head == null){
    return null;
    }
    ListNode dummyHead = new ListNode();
    dummyHead.next = head;
    ListNode cur = dummyHead;
    while(cur.next != null){
      if (cur.next.val == val){
        cur.next = cur.next.next;
      }
      cur = cur.next;
    }
    return dummyHead.next;
  }
}
